<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
    <script src="./lib/vue-router-3.0.1.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/mycount">主组件</router-link>
        <router-view></router-view>
    </div>
    <template id="tmp1">
        <div>
            <h1>我是主组件</h1>
            <!-- 子组件中的路径 需要添加父组件的路径 -->
            <router-link to="/mycount/login">登录</router-link>
            <router-link to="/mycount/register">注册</router-link>
            <router-view></router-view>
        </div>
    </template>
    <script>
        var mycount = {
            template : '#tmp1'
        }
        var login = {
            template : '<h2>我是登录组件</h2>'
        }
        var register = {
            template : '<h2>我是注册组件</h2>'
        }
        const router = new VueRouter({
            routes : [

                {   path : '/mycount' ,
                    component : mycount ,
                    // 主组件添加子组件,添加 children 对象,其对象不需要添加 / ,因为这里的路径不需要从根目录开始
                    
                    children : [
                        {path : 'login' , component : login},
                        {path : 'register' , component : register}
                    ]
                },
            ]
        })
        new Vue({
            el : '#app',
            data : {

            },
            methods : {

            },
            router
        })
    
    </script>
</body>
</html>